<template>
  <div class="user-profile">
    <!-- 导航栏 -->
    <van-nav-bar
      class="page-nav-bar"
      left-arrow
      title="个人资料"
      @click-left="$router.back()"
    ></van-nav-bar>
    <!-- /导航栏 -->

    <!-- 个人信息 -->
    <van-cell title="头像" is-link>
      <van-image class="avatar" fit="cover" round :src="user.photo" />
    </van-cell>
    <van-cell
      title="昵称"
      :value="user.name"
      is-link
      @click="isUpdataNameShow = true"
    ></van-cell>
    <van-cell
      title="性别"
      :value="user.gender === 0 ? '男' : '女'"
      is-link
      @click="isUpdataGenderShow = true"
    ></van-cell>
    <van-cell
      title="生日"
      :value="user.birthday"
      is-link
      @click="isUpdataBirthdayShow = true"
    ></van-cell>

    <!-- 编辑昵称 -->
    <van-popup
      v-model="isUpdataNameShow"
      style="height: 100%"
      position="bottom"
    >
      <updataName
        v-if="isUpdataNameShow"
        @close="isUpdataNameShow = false"
        v-model="user.name"
      />
    </van-popup>

    <!-- 编辑性别 -->
    <van-popup v-model="isUpdataGenderShow" position="bottom">
      <updateGender
        @close="isUpdataGenderShow = false"
        v-model="user.gender"
        v-if="isUpdataGenderShow"
      />
    </van-popup>

    <!-- 编辑生日 -->
    <van-popup v-model="isUpdataBirthdayShow" position="bottom">
      <updateBirthday
        v-model="user.birthday"
        @close="isUpdataBirthdayShow = false"
      />
    </van-popup>
  </div>
</template>

<script>
import { getUserProfile } from '@/api/user';
import updataName from './components/updata-name.vue';
import updateGender from './components/updata-gender.vue';
import updateBirthday from './components/updata-birthday.vue';
export default {
  name: 'UserProfile',
  components: {
    updataName,
    updateGender,
    updateBirthday
  },
  // props: {
  //   userId: {
  //     type: [Number, String, Object],
  //     required: true
  //   }
  // },
  data() {
    return {
      user: {}, // 个人信息
      isUpdataNameShow: false, // 更改昵称弹层控制器
      isUpdataGenderShow: false, // 更改性别弹层
      isUpdataBirthdayShow: false // 更改生日弹层
    };
  },
  computed: {},
  watch: {},
  created() {
    this.loadUserProfile();
  },
  mounted() {},
  methods: {
    async loadUserProfile() {
      try {
        const { data } = await getUserProfile();
        console.log(data);
        this.user = data.data;
      } catch (err) {
        this.$toast.fail('获取数据失败');
      }
    }
  }
};
</script>

<style scoped lang="less">
.user-profile {
  /deep/ .page-nav-bar {
    background-color: rgb(237, 132, 33) !important;
  }
  .avatar {
    height: 60px;
    width: 60px;
  }
  .van-popup {
    background-color: #f5f7f9;
  }
}
</style>
